//
//  WKPlanBookListCell.m
//  WKMaybell
//
//  Created by 何文虎 on 2018/12/15.
//  Copyright © 2018 何文虎. All rights reserved.
//

#import "WKPlanBookListCell.h"

@interface WKPlanBookListCell ()
@property(nonatomic,strong)UIImageView *beforeImageView;
@property(nonatomic,strong)UIImageView *afterImageView;
@property(nonatomic,strong)UILabel *afterLb;
@property(nonatomic,strong)UILabel *beforeLb;
@property(nonatomic,strong)UILabel *titleLb;
@property(nonatomic,strong)UILabel *contentLb;
@property(nonatomic,strong)UIButton *changeBtn;
@end

@implementation WKPlanBookListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setup];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setup{
    UIView *bgimgview = [[UIView alloc]initWithFrame:CGRectMake(12, 15, 98*2, 98)];
    bgimgview.layer.cornerRadius = 5;
    bgimgview.layer.masksToBounds = YES;
    [self.contentView addSubview:bgimgview];
    
    [bgimgview addSubview:self.beforeImageView];
    [self.beforeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.with.mas_offset(0);
        make.width.mas_offset(98);
    }];
    
    [self.beforeImageView addSubview:self.beforeLb];
    [self.beforeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.with.mas_offset(-2);
        make.bottom.with.mas_offset(2);
        make.width.mas_offset(40);
        make.height.mas_offset(20);
    }];
    
    [bgimgview addSubview:self.afterImageView];
    [self.afterImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.with.mas_offset(0);
        make.width.mas_offset(98);
    }];
    
    [self.afterImageView addSubview:self.afterLb];
    [self.afterLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.with.mas_offset(2);
        make.bottom.with.mas_offset(2);
        make.width.mas_offset(40);
        make.height.mas_offset(20);
    }];
    
    [self.contentView addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(bgimgview.mas_right).offset(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(15);
    }];
    

    
    [self.contentView addSubview:self.changeBtn];
    [self.changeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(bgimgview.mas_right).offset(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(24);
        make.bottom.mas_equalTo(-16);
    }];
    
    [self.contentView addSubview:self.contentLb];
    [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_titleLb.mas_bottom).offset(10);
        make.left.mas_equalTo(bgimgview.mas_right).offset(12);
        make.right.mas_equalTo(-12);
        make.bottom.mas_equalTo(_changeBtn.mas_top).offset(-10);
    }];
    
    
    _contentLb.numberOfLines = 0;
    _contentLb.preferredMaxLayoutWidth = ScreenWidth - 24 -12 -98-98;
    [_contentLb sizeToFit];
    
    _beforeImageView.contentMode = UIViewContentModeScaleAspectFill;
    _beforeImageView.layer.masksToBounds = YES;
//    _beforeImageView.layer.cornerRadius = 5;
    _afterImageView.contentMode = UIViewContentModeScaleAspectFill;
    _afterImageView.layer.masksToBounds = YES;
//    _afterImageView.layer.cornerRadius = 5;
    
    [_beforeImageView sd_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544867930401&di=f4c29df2f5d67bc01980671cec5af653&imgtype=0&src=http%3A%2F%2Fi1.hdslb.com%2Fbfs%2Farchive%2Fd5afc4104126e06641179c26cbce97dd66ade9d8.jpg"]];
    [_afterImageView sd_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1544867961442&di=5854d8a7becaea8e38b5ed950cc65a15&imgtype=0&src=http%3A%2F%2Fa2.att.hudong.com%2F54%2F32%2F01300000559649125904327623943_s.jpg"]];
    
    _titleLb.text = @"#祛痘日记";
    _contentLb.text = @"伯恩·约翰·安德森（瑞典语：Björn Johan Andrésen，芬兰语：Bjørn Juhana Andresen )，1955年1月26日生于瑞典首都斯德哥尔摩。伯恩除了作为演员，也是职业音乐家，曾与斯文埃里克斯舞蹈乐队巡回演出";


    
    
}

#pragma mark - 更新日记
- (void)changeAction:(UIButton*)sender{
    if (self.changeBtn) {
        self.changeBlock();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (UIImageView *)beforeImageView{
    if (!_beforeImageView) {
        _beforeImageView = [[UIImageView alloc]init];
    }
    return _beforeImageView;
}

- (UIImageView *)afterImageView{
    if (!_afterImageView) {
        _afterImageView = [[UIImageView alloc]init];
    }
    return _afterImageView;
}

- (UILabel *)beforeLb{
    if (!_beforeLb) {
        _beforeLb = [[UILabel alloc]init];
        _beforeLb.textColor = UIColorFromHex(0xFFFFFF);
        _beforeLb.font = PFSC_RegularFont(10);
        _beforeLb.layer.masksToBounds = YES;
        _beforeLb.layer.cornerRadius = 5;
        _beforeLb.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
        _beforeLb.text = @"Before";
        _beforeLb.textAlignment = NSTextAlignmentCenter;
    }
    return _beforeLb;
}

- (UILabel *)afterLb{
    if (!_afterLb) {
        _afterLb = [[UILabel alloc]init];
        _afterLb.textColor = UIColorFromHex(0xFFFFFF);
        _afterLb.font = PFSC_RegularFont(10);
        _afterLb.layer.masksToBounds = YES;
        _afterLb.layer.cornerRadius = 5;
        _afterLb.backgroundColor = UIColorFromHex(0xF54050);
        _afterLb.text = @"Affter";
        _afterLb.alpha = 0.6;
        _afterLb.textAlignment = NSTextAlignmentCenter;
    }
    return _afterLb;
}



- (UILabel *)titleLb{
    if (!_titleLb) {
        _titleLb = [[UILabel alloc]init];
        _titleLb.textColor = UIColorFromHex(0x3c3c3c);
        _titleLb.font = PFSC_MediumFont(15);
    }
    return _titleLb;
}

- (UILabel *)contentLb{
    if (!_contentLb) {
        _contentLb = [[UILabel alloc]init];
        _contentLb.textColor = UIColorFromHex(0x979797);
        _contentLb.font = PFSC_RegularFont(12);
    }
    return _contentLb;
}

- (UIButton *)changeBtn{
    if (!_changeBtn) {
        _changeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_changeBtn setTitle:@"更新日记" forState:UIControlStateNormal];
        [_changeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _changeBtn.titleLabel.font = PFSC_MediumFont(12);
        _changeBtn.layer.masksToBounds = YES;
        _changeBtn.layer.cornerRadius = 12;
        [_changeBtn addTarget:self action:@selector(changeAction:) forControlEvents:UIControlEventTouchUpOutside];
        _changeBtn.backgroundColor = BACK_COLOR;
    }
    return _changeBtn;
}

@end
